const Win = require('ember-cli/lib/utilities/windows-admin');
const fs = require('fs');
const { electronProjectPath } = require('../utils/build-paths');
const checkDependencies = require('../utils/check-dependencies');
const { upgradingUrl } = require('../utils/documentation-urls');
const SilentError = require('silent-error');

module.exports = async function prepareRun(project) {
  if (!fs.existsSync(electronProjectPath)) {
    return Promise.reject(
      new SilentError(
        [
          `No './${electronProjectPath}' folder found. This folder must exist and`,
          `contain an electron-forge project. It should have been generated by`,
          `ember-electron's blueprint when you first ran 'ember install`,
          `ember-electron'. If you are upgrading from ember-electron v2, you`,
          `should read the upgrading documentation at ${upgradingUrl}.`,
        ].join(' '),
      ),
    );
  }

  await checkDependencies(project);

  // Tell our addon that we're building for electron, so it should inject
  // shims, etc.
  process.env.EMBER_CLI_ELECTRON = true;

  await Win.checkIfSymlinksNeedToBeEnabled(project.ui);
};
